"""
@author: Alexander Fruehwirth
@version: 1.0
"""


from website.models import Recipe

from django.contrib.auth.models import User

from website import views

from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse

class RssRecipeFeed(Feed):
    title = "Recipes RSS Reader"
    link = "/rss/"
    description = "Get the newest Recipes"

    def items(self):
        """ Gets last 20 Recipes """
        return Recipe.objects.order_by('-pub_date')[:20]
    
    def item_link(self, item):
        """ returns link for single recipe """
        return reverse('website.views.recipe', args=[item.pk])
    
    def item_author_name(self, item):
        """ returns username for single recipe"""
        return User.objects.get(pk = item.user_id).username
    
    
    def item_description(self, item):
        """ builds description for single recipe"""

        content = "<p>by "+ self.item_author_name(item)+  "</p><p>"+ item.difficulty + " | " + item.vegetarian+" | " + views.avg_ratings(self, item.pk)+"</p><p>"+item.description+"</p>"
        
        
        return content
    
    def item_title(self, item):
        """ returns title for single recipe"""

        return item.title 